<template>
	<view class="has-pdlr-20">
		<view class="is-bank has-pd-20 has-mgb-10" v-for="(item,index) in bank" :key="index">
			<view class="is-blue-color">{{item.bank_name}}</view>
			<view class="">
				支行：<text>{{item.bank_cmp}}</text>
			</view>
			<view class="">
				账号：<text>{{item.bank_no}}</text>
			</view>
			<view class="">
				姓名：<text>{{item.bank_user}}</text>
			</view>
			<view class="">
				手机：<text>{{item.bank_tel}}</text>
			</view>
			<view class="">
				备注：<text>{{item.bank_memo}}</text>
				<button type="warn" size="mini" @tap="delbank" :data-id="item.id" class="has-floatr">删除</button>
			</view>
		</view>
		<view class="is-add is-center" @tap = "addbank">
			<image src="../../static/img/common/plus_ico.png" mode="" class="plus-ico"></image>
			<text>添加</text>
		</view>
		<view>
		    <show-modal></show-modal>
		</view>
	</view>
</template>

<script>
	var _self;
	export default{
		data(){
			return{
				foxtoken:'',
				'bank':[],
				userinfo:[],
				user_card_rz:0
			}
		},
		onShow:function(e){
			let pages = getCurrentPages();
			let currPage = pages[pages.length-1];
			if (currPage.data.isDoRefresh == true){
				currPage.data.isDoRefresh = false;
				this.getbank();
			}
		},
		onLoad(){
			_self = this;
			this.getbank();
		},
		methods:{
			getbank(){
				let info = this.service.getfox();
				if(info[0]){
					let user_token = info[0]['foxtoken'];
					this.foxtoken = user_token;
					// console.log(user_tel)
					uni.request({
						url: this.service.FOX_URL + 'diamond/get_bank',
						method:'POST',
						data: {
							user_key: user_token,
							page:1,
							limit:100
						},
						dataType:'json',
						header:{
							'content-type':'application/x-www-form-urlencoded',
						},
						success: res => {
							var rest = res.data;
							// console.log(rest)
							if(rest.code == '200'){
								if(rest.data.list){
									_self.bank = rest.data.list;
								}else{
									uni.showToast({
										title:rest.message,
										icon:'none',
										mask:true
									})
								}
							}
						}
					})
				}else{
					uni.reLaunch({
						url:'../logon/login'
					})
				}
			},
			addbank(){
				uni.navigateTo({
					url:'./bank_set'
				})
				/**是否需要身份认证**/
				// let info = this.service.getfox();
				// this.foxtoken = info[0]['foxtoken'];
				// uni.request({
				// 	url: this.service.FOX_URL + 'diamond/get_userinfo',
				// 	method:'POST',
				// 	data: {
				// 		user_key: this.foxtoken
				// 	},
				// 	dataType:'json',
				// 	header:{
				// 		'content-type':'application/x-www-form-urlencoded',
				// 	},
				// 	success: res => {
				// 		// var rest = JSON.stringify(res);
				// 		// console.log(res)
				// 		var rest = res.data;
				// 		if(rest.status == 'success'){
				// 			this.userinfo = rest.msg;
				// 			this.user_card_rz = this.userinfo['user_card_rz']
				// 			if(this.user_card_rz == 0){
				// 				this.$showModal({
				// 				    title: '提示',
				// 				    content: '您尚未实名认证，去认证',
				// 					showCancel:false,
				// 					confirmText:'去认证',
				// 				    success: function (res) {
				// 				        if (res.confirm) {
				// 				            uni.navigateTo({
				// 				            	url:'../member/setup'
				// 				            })
				// 				        }
				// 				    }
				// 				});
				// 			}else{
				// 				uni.navigateTo({
				// 					url:'./bank_set'
				// 				})
				// 			}
				// 		}
				// 	}
				// })
			},
			delbank: function(e){
				var id = e.currentTarget.dataset.id;
				let info = this.service.getfox();
				var foxtoken = info[0]['foxtoken'];
				this.$showModal({
				    title: '提示',
				    content: '您确定要删除这个银行卡么',
					cancelText:'放弃',
					confirmText:'是的',
				    success: function (res) {
				        if (res.confirm) {
				            uni.request({
				            	url: _self.service.FOX_URL + 'diamond/del_bank',
				            	method:'POST',
				            	data: {
				            		user_key: foxtoken,
				            		id: id
				            	},
				            	dataType:'json',
				            	header:{
				            		'content-type':'application/x-www-form-urlencoded',
				            	},
				            	success: res => {
				            		var rest = res.data;
				            		if(rest.status == 'success'){
										uni.showToast({
											title:rest.msg,
											icon:'none',
											mask:true
										})
										_self.getbank();
				            		}else{
				            			uni.showToast({
				            				title:rest.msg,
				            				icon:'none',
				            			})
				            		}
				            	}
				            })
				        } else if (res.cancel) {
				            console.log('用户点击取消');
				        }
				    }
				});
			}
		}
	}
</script>

<style>
	.is-bank{
		background: #FFFFFF;
	}
	.is-add{
		background: #FFFFFF;
		height: 120rpx;
		line-height: 120rpx;
	}
	.plus-ico{
		width:40rpx;
		height: 40rpx;
		vertical-align: middle;
		margin-right: 20rpx;
	}
</style>
